package com.zy.service.bs.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zy.dao.bs.BbsTypeDao;
import com.zy.entity.enums.StatusEnum;
import com.zy.entity.bs.BbsType;
import com.zy.pojo.query.bs.BbsTypeQuery;
import com.zy.pojo.vos.common.PageVo;
import com.zy.service.base.impl.BaseServiceImpl;
import com.zy.service.bs.BbsTypeService;
import com.zy.utils.DateUtil;

@Service("bbsTypeService")
public class BbsTypeServiceImpl extends BaseServiceImpl<BbsType> implements BbsTypeService {

	@Autowired
	private BbsTypeDao bbsTypeDao;

	@Override
	public PageVo pageBbsType(BbsTypeQuery bbsTypeQuery, Integer start, Integer limit) {
		return new PageVo(start, limit, this.bbsTypeDao.countBbsType(bbsTypeQuery), this.bbsTypeDao.listBbsType(bbsTypeQuery, start, limit));
	}

	@Override
	public void saveBbsType(BbsType bbsType) {
		long time = DateUtil.getTime();
		bbsType.setCreateTime(time);
		bbsType.setModifyTime(time);
		bbsType.setStatus(StatusEnum.NORMAL.getValue());
		this.bbsTypeDao.save(bbsType);
	}
	
	@Override
	public void updateBbsType(BbsType bbsType) {
		bbsType.setModifyTime(DateUtil.getTime());
		this.bbsTypeDao.updateByPrimaryKeySelective(bbsType);
	}

	@Override
	public void removeBbsType(long id) {
		try {
			this.bbsTypeDao.removeByPrimaryKey(id);
		} catch (Exception e) {
			log.info(e.getMessage(),e);
			BbsType bbsType = new BbsType();
			bbsType.setId(id);
			bbsType.setModifyTime(DateUtil.getTime());
			bbsType.setStatus(StatusEnum.DELETE.getValue());
			this.bbsTypeDao.updateByPrimaryKeySelective(bbsType);
		}
	}

	@Override
	public void recover(long id) {
		BbsType bbsType = new BbsType();
		bbsType.setId(id);
		bbsType.setModifyTime(DateUtil.getTime());
		bbsType.setStatus(StatusEnum.NORMAL.getValue());
		this.bbsTypeDao.updateByPrimaryKeySelective(bbsType);
	}

}
